import time
def main_ui():
    print(f"欢迎进入登陆系统".center(50, "*"))
    print("1.登录".center(50, " "))
    print("2.注册".center(50, " "))
    print("3.退出".center(50, " "))
    print("".center(50, "*"))

class AccountCard:

    def __init__(self, card_no):
        self.card_no = card_no          # 卡号
    def __repr__(self):
        """打印信息"""
        return f'用户名：{self.card_no}\n' \

class ATM:

    def __init__(self):
        self.accounts = {
            'zhangsan': {'password': '123321', 'balance': 1200.0, 'valid': True},
            'lisi': {'password': '123456', 'balance': 54321.0, 'valid': True},
            'wangwu': {'password': '147258', 'balance': 0.0, 'valid': False}
        }
        self.ATM_balance = 10000000
        self.ATM_region = "changsha"
        self.current_card = None        # 当前ATM机识别的银行卡
        self.current_account = None     # 当前ATM机内的账户


    def login(self, card):  # 登录
        if card.card_no in self.accounts:
            self.current_account = self.accounts[card.card_no]
            for _ in range(3):
                password = input("请输入账户密码：")
                if password == self.current_account["password"]:
                    # 若输入密码成功，当前ATM识别的银行卡为当前插入的卡
                    self.current_card = card
                    return True
                else:
                    print(f"密码错误，您还有{2-_}次尝试的机会！")
            else:
                print("该账户被冻结24小时，如有疑问，请联系工作人员。")
        else:
            print("该账户不存在!")
            return False

    def show_balance(self):  # 查询余额
        if self.current_account:
            print(f"账余额为：{self.current_account['balance']}RMB")
            print(f"当前ATM机还剩{self.ATM_balance}RMB")

    def deposited(self, money):  # 存钱
        if self.current_account and money > 0:
            self.current_account['balance'] += money
            self.ATM_balance += money
            print("正在处理，请稍后...")
            time.sleep(3)
            print("存款成功")
            print(f"当前ATM机还剩{self.ATM_balance}RMB")
        else:
            return False

    def drawback(self, money):  # 取钱
        if self.current_account and money <= self.current_account['balance']:
            self.current_account['balance'] -= money
            self.ATM_balance -= money
            print("正在处理，请稍后...")
            time.sleep(3)
            print("请取走您的钞票")
            print(f"当前ATM机还剩{self.ATM_balance}RMB")
            return True
        else:
            print("账户余额不足！！！")
            return False

    def card_retrieve(self):  # 退卡
        print("正在退卡，请稍后...")
        time.sleep(2)
        print("请取走您的银行卡。")
        self.current_account = None
        self.current_card = Nones
    def register(self, username, passwd):
        print("注册成功！")
        self.username = username
        self.passwd = passwd
        self.accounts[username] = {'passwd':passwd, 'balance':10}
        print(f"已新建账户：{username},当前余额：{self.accounts[username].get('balance')}")

def main():

    main_ui()
    option = input("请输入要进行的选项：")
    atm = ATM()
    while True:
        if option == "1":
            username = input("请输入用户名：")
            my_card = AccountCard(username)
            print(my_card)
            if atm.login(my_card):
                while True:
                    print("请选择业务".center(50,'*'))
                    select_option = eval(input("1.查询余额\n2.存款\n3.取款\n4.退卡\n请输入要进行操作的序号："))
                    print("*" * 50)
                    if select_option == 1:
                        atm.show_balance()
                    elif select_option == 2:
                        deposit_money = eval(input("请输入存款金额："))
                        atm.deposited(money=deposit_money)
                    elif select_option == 3:
                        drawback_money = eval(input("请输入要取走的金额："))
                        atm.drawback(money=drawback_money)
                    elif select_option == 4:
                        atm.card_retrieve()
                        exit()
                    else:
                        print("操作有误，请重新输入！！！")
        elif option == "2":
            username1 = input("请输入要注册的用户名：")
            passwd1 = input("请输入六位数字密码：")
            atm.register(username1, passwd1)
            main_ui()
            option = input("登录请按1：")
            print(atm.accounts)
        elif option == "3":
            atm.card_retrieve()
            exit()
main()
